namespace PickGold.Charting.Design
{
    using System;
    using System.ComponentModel;
    using System.Drawing;

    internal class ColorExtendedArrayPropertyDescriptor : PropertyDescriptor
    {
        private PropertyDescriptor _basePropertyDescriptor;

        public ColorExtendedArrayPropertyDescriptor(PropertyDescriptor basePropertyDescriptor) : base(basePropertyDescriptor)
        {
            this._basePropertyDescriptor = basePropertyDescriptor;
            AttributeCollection attributes = AttributeCollection.FromExisting(basePropertyDescriptor.Attributes, new Attribute[] { new TypeConverterAttribute(typeof(ColorExtendedArrayConverter)) });
            Attribute[] array = new Attribute[attributes.Count];
            attributes.CopyTo(array, 0);
            base.AttributeArray = array;
        }

        public override bool CanResetValue(object component)
        {
            return this._basePropertyDescriptor.CanResetValue(component);
        }

        public override object GetValue(object component)
        {
            Color[] colorArray = this._basePropertyDescriptor.GetValue(component) as Color[];
            if (colorArray == null)
            {
                return new ColorExtended[0];
            }
            ColorExtended[] extendedArray = new ColorExtended[colorArray.Length];
            for (int i = 0; i < colorArray.Length; i++)
            {
                extendedArray[i] = new ColorExtended(colorArray[i]);
            }
            return extendedArray;
        }

        public override void ResetValue(object component)
        {
            this._basePropertyDescriptor.ResetValue(component);
        }

        public override void SetValue(object component, object value)
        {
            ColorExtended[] extendedArray = value as ColorExtended[];
            if (extendedArray != null)
            {
                Color[] colorArray = new Color[extendedArray.Length];
                for (int i = 0; i < extendedArray.Length; i++)
                {
                    colorArray[i] = extendedArray[i].Value;
                }
                this._basePropertyDescriptor.SetValue(component, colorArray);
            }
        }

        public override bool ShouldSerializeValue(object component)
        {
            return this._basePropertyDescriptor.ShouldSerializeValue(component);
        }

        public override Type ComponentType
        {
            get
            {
                return this._basePropertyDescriptor.ComponentType;
            }
        }

        public override bool IsReadOnly
        {
            get
            {
                return this._basePropertyDescriptor.IsReadOnly;
            }
        }

        public override Type PropertyType
        {
            get
            {
                return typeof(ColorExtended[]);
            }
        }
    }
}

